using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Messenger.Models;

namespace Messenger.Services;

public class PoetryService : IPoetryService {
    private List<Poetry> _poetries = new() {
        new Poetry
            { Id = 1, Name = "Name 1", Content = "Content 1" },
        new Poetry
            { Id = 2, Name = "Name 2", Content = "Content 2" },
        new Poetry
            { Id = 3, Name = "Name 3", Content = "Content 3" }
    };

    public IEnumerable<Poetry> GetPoetries() => _poetries;

    public void AddPoetry(Poetry poetry) {
        _poetries.Add(poetry);
        WeakReferenceMessenger.Default.Send(
            new PoetryAddedMessage(poetry));
    }
}

public class PoetryAddedMessage : ValueChangedMessage<Poetry> {
    public PoetryAddedMessage(Poetry value) : base(value) { }
}